package com.vay.de.dang.online.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.vay.de.dang.online.VnApp;
import com.vay.de.dang.online.resp.RApplyBillDto;
import com.vay.de.dang.online.util.VnUtil;
import com.vay.de.dang.online.R;

public class DialogBillDetail extends DialogBottom {

    private LayoutInflater inflater;
    private TextView pMoney;
    private LinearLayout itemLayout;

    public DialogBillDetail(Context context) {
        super(context);
        autoWidth(1.0f);
        setContentView(R.layout.dialog_bill_detail);
        inflater = getLayoutInflater();
        pMoney = findViewById(R.id.p_money);
        itemLayout = findViewById(R.id.item_layout);

        findViewById(R.id.bnt_close).setOnClickListener(view -> {
            dismiss();
        });
    }

    public void showBill(String state, RApplyBillDto entity) {
        pMoney.setText(VnUtil.toMoneyStr2(entity.getFinancialProductsAmount()));
        itemLayout.removeAllViews();
        // 贷款金额，贷款期限，贷款时间，
        if ("1".equals(state) || "2".equals(state) || "3".equals(state)) {
            createItem(VnApp.getStr(R.string.label_detail_term), entity.getFinancialProductsTerm() + " " + VnApp.getStr(R.string.label_days));
            createItem(VnApp.getStr(R.string.label_detail_apply_time), entity.getApplyTime());
            int withdrawalType = entity.getWithdrawalType();
            if (withdrawalType == 1) {
                createItem(VnApp.getStr(R.string.label_detail_withdrawal_type), VnApp.getStr(R.string.label_detail_withdrawal_1));
            } else if (withdrawalType == 2) {
                createItem(VnApp.getStr(R.string.label_detail_withdrawal_type), VnApp.getStr(R.string.label_detail_withdrawal_2));
            } else {
                createItem(VnApp.getStr(R.string.label_detail_withdrawal_type), VnApp.getStr(R.string.label_detail_withdrawal_3));
            }
        }
        // 贷款金额，贷款期限, 未还金额，应还时间，，逾期金额
        else if ("4".equals(state) || "5".equals(state)) {
            createItem(VnApp.getStr(R.string.label_detail_term), entity.getFinancialProductsTerm() + " " + VnApp.getStr(R.string.label_days));
            createItem(VnApp.getStr(R.string.label_detail_remain), VnUtil.toMoneyStr2(entity.getDueMoney()));
            createItem(VnApp.getStr(R.string.label_detail_first_return), entity.getShouldReturnDate());
            createItem(VnApp.getStr(R.string.label_detail_overdue_money), VnUtil.toMoneyStr2(entity.getOverdueMoney()));
        }
        // 贷款金额，贷款期限，结清时间
        else if ("6".equals(state)) {
            createItem(VnApp.getStr(R.string.label_detail_term), entity.getFinancialProductsTerm() + " " + VnApp.getStr(R.string.label_days));
            createItem(VnApp.getStr(R.string.label_detail_real_return_date), entity.getRealReturnDate());
        }
        show();
    }

    private void createItem(String label, String value) {
        View iv = inflater.inflate(R.layout.dialog_bill_detail_item, null);
        TextView labelTv = iv.findViewById(R.id.item_label);
        TextView valueTv = iv.findViewById(R.id.item_value);
        labelTv.setText(label);
        valueTv.setText(value);
        itemLayout.addView(iv);
    }
}
